﻿{include file='pub@pub/header'/}
<title>商品列表</title>
<style>
    .td-manage a{
        display: inline-block;
    }
</style>
</head>
<body class="pos-r">
<div>
    <nav class="breadcrumb">{$breadNav} <a class="btn btn-success radius r btn-refresh" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
    <div class="page-container">
        <div class="text-c">
            <form action="" method="get">
                商品名称：<input type="text" name="product_name" autocomplete="false" value="{$param.product_name|default=''}" id="" placeholder=" 商品名称" style="width:250px" class="input-text">
                分类：<span class="select-box" style="width: 200px;">
                        <select name="cate_id" class="input select">
                            <option value="">全部</option>
                            <option value="0" {if isset($param['cate_id']) and '0'===$param.cate_id}selected{/if}>未分类</option>
                            {foreach $cate_list as $key=>$val}
                            <option value="{$key}" {if isset($param['cate_id']) and $key eq $param.cate_id}selected{/if}>{$val}</option>
                            {/foreach}
                        </select>
                    </span>
            <button class="btn btn-success" type="submit"><i class="Hui-iconfont">&#xe665;</i> 搜商品
            </button>
            </form>
        </div>
        <div class="cl pd-5 bg-1 bk-gray mt-20">
            <span class="l">
                <a class="btn btn-primary radius" onclick="product_add('添加商品','{:url(\'Product/add\')}')" href="javascript:;">
                    <i class="Hui-iconfont">&#xe600;</i> 添加商品
                </a>
            </span>
            <span class="r">共有数据：<strong>{$totalNum}</strong> 条</span>
        </div>
        <div class="mt-20">
            <table class="table table-border table-bordered table-bg table-hover table-sort">
                <thead>
                    <tr class="text-c">
                        <th width="40">ID</th>
                        <th width="100">名称</th>
                        <th width="100">排序(<span style="font-size: 12px;">数值越小越靠前</span>)</th>
                        <th width="100">分类</th>
                        <th width="100">单位</th>
                        <th width="100">规格</th>
                        <th width="100">热销商品</th>
                        <th width="100">限时抢购/秒杀</th>
                        <th width="100">销售属性</th>
                        <th width="100">库存剩余</th>
                        <th width="200">操作</th>
                    </tr>
                </thead>
                <tbody>
                {foreach $list as $item}
                <tr class="text-c va-m">
                    <td>{$item.id}</td>
                    <td class="text-l">
                        {$item.product_name}
                    </td>
                    <td>
                        <input class="input input-text" type="text" onblur="changeOrd(this, '{$item.id}')" value="{$item.ord}" data-ori="{$item.ord}">
                    </td>
                    <td>
                        <span class="select-box">
                            <select class="select" onchange="changeCate('{$item.id}', this)">
                                <option value="0">未分类</option>
                                {foreach $cate_list as $key=>$val}
                                <option value="{$key}" {if $key eq $item.cate_id}selected{/if}>{$val}</option>
                                {/foreach}
                            </select>
                        </span>
                    </td>
                    <td>
                        {$item.unit}
                    </td>
                    <td>
                        {$item.attr}
                    </td>
                    <td>
                        <input onchange="modify(this, '{$item.id}', 0)" type="checkbox" {if $item.is_hot eq 1} checked {/if}>
                    </td>
                    <td>
                        <input onchange="modify(this, '{$item.id}', 1)" type="checkbox" {if $item.is_sec eq 1} checked {/if}>
                    </td>
                    <td>
                        <button class="btn btn-primary radius size-MINI" onclick="layer_show('销售属性编辑', '{:url(\'Product/saleAttr\', [\'product_id\'=>$item.id])}')">查看</button>
                    </td>
                    <td>
                        {$item.stock}
                    </td>
                    <td class="td-manage">
                        <a style="text-decoration:none" class="ml-5"
                           onClick="product_edit('产品编辑','{:url(\'Product/edit\', [\'product_id\'=>$item.id])}')"
                           href="javascript:;" title="编辑">
                            <i class="Hui-iconfont">&#xe6df;</i>编辑
                        </a>
                        {if $item.is_up eq 0}
                        <a style="text-decoration:none" class="ml-5"
                           onClick="changeUpStatus('{$item.id}', 1)"
                           href="javascript:;" title="产品上架">
                            <i class="Hui-iconfont Hui-iconfont-shangjia"></i>上架
                        </a>
                        {else/}
                        <a style="text-decoration:none" class="ml-5"
                           onClick="changeUpStatus('{$item.id}', 0)"
                           href="javascript:;" title="产品下架">
                            <i class="Hui-iconfont Hui-iconfont-shangjia"></i>下架
                        </a>
                        {/if}
                        <a style="text-decoration:none" class="ml-5"
                           onClick="layer_show('商品入库','{:url(\'Product/stockAdd\', [\'product_id\'=>$item.id])}')"
                           href="javascript:;" title="商品入库">
                            <i class="Hui-iconfont Hui-iconfont-add4"></i>商品入库
                        </a>
                        <a style="text-decoration:none" class="ml-5"
                           onClick="layer_show('商品出入库记录','{:url(\'Product/stockList\', [\'product_id\'=>$item.id])}')"
                           href="javascript:;" title="出入库记录">
                            <i class="Hui-iconfont Hui-iconfont-list"></i>出入库记录
                        </a>
                        <a style="text-decoration:none" class="ml-5"
                           onClick="matchProduct('{$item.id}')"
                           href="javascript:;" title="商品配货">
                            <i class="Hui-iconfont Hui-iconfont-list"></i>商品配货
                        </a>
                        <a style="text-decoration:none" class="ml-5"
                           onClick="dispatchProduct('{$item.id}')"
                           href="javascript:;" title="商品配送">
                            <i class="Hui-iconfont Hui-iconfont-list"></i>商品配送
                        </a>
                        <a style="text-decoration:none" class="ml-5" onClick="product_del(this,'{$item.id}')"
                           href="javascript:;" title="删除">
                            <i class="Hui-iconfont">&#xe6e2;</i>删除
                        </a>
                    </td>
                </tr>
                {/foreach}
                </tbody>
            </table>
            {$list->render()}
        </div>
    </div>
</div>

{include file='pub@pub/footer'/}
<script type="text/javascript">
    // $('.table-sort').dataTable();
    //配送当前已买商品
    function dispatchProduct(id){
        layer.confirm("确定配送当前商品？", function () {
            $.post("{:url('dispatchProduct')}", {id:id}, function (res) {
                layer.msg(res.msg);
            });
        })
    }
    //当前商品配货
    function matchProduct(id){
        layer.confirm("确定配货当前商品？", function(){
            $.post('{:url("matchProduct")}', {product_id:id}, function(res){
                layer.msg(res.msg);
            });
        })
    }
    function changeUpStatus(id, type){
        var msg = type==1?"确定上架该商品？":"确定下架该商品？";
        layer.confirm(msg, function(){
            $.post('{:url("Product/upstair")}', {id:id, type:type}, function(res){
                if(res.code == 1){
                    location.reload();
                }
                layer.msg(res.msg);
            })
        })
    }

    /* 更改热销，抢购 */
    function modify(o, pid, type){
        var checked = $(o).prop("checked");
        $.post('{:url("modifyC")}', {pid:pid, checked:checked?1:0, type:type}, function (res) {
            if(res.code != 1){
                $(o).prop("checked", !checked);
            }
            layer.msg(res.msg);
        });
    }
    /* 更改商品排序 */
    function changeOrd(o, pid){
        var ord = $(o).val();
        var ori_ord = $(o).data("ori");
        if(ord == ori_ord){
            layer.msg("更改成功");
            return;
        }else{
            $.post('{:url("changeOrd")}', {pid:pid, ord:ord}, function (res) {
                if(res.code != 1){
                    $(o).val(ori_ord);
                }
                layer.msg(res.msg);
            });
        }


    }
    
    function changeCate(pid,o){
        let cate_id = $(o).val();
        $.post("{:url('changeCate')}", {id:pid, cate_id:cate_id}, function (res) {
            if(res.code == 1){
                layer.msg("修改成功");
            }else{
                layer.msg("修改失败");
            }
        });
    }

    /*产品-添加*/
    function product_add(title, url) {
        var index = layer.open({
            type: 2,
            title: title,
            content: url,
            area:["800px", "600px"]
        });
        // layer.full(index);
    }

    /*产品-编辑*/
    function product_edit(title, url) {
        var index = layer.open({
            type: 2,
            title: title,
            content: url,
            area:["800px", "600px"]
        });
        // layer.full(index);
    }

    /*产品-删除*/
    function product_del(obj, id) {
        layer.confirm('确认要删除吗？', function (index) {
            $.post("{:url('Product/delData')}", {idstr:id}, function (res) {
                if(res.code == 1){
                    layer.msg('删除成功');
                    $(obj).parents('tr').remove();
                }else{
                    layer.msg(res.msg);
                }
            });
        });
    }
</script>
</body>
</html>